package Flyweight

type Flyweight struct {
	Name string
}

func NewFlyweight(name string) *Flyweight {
	return &Flyweight{Name: name}
}

type FlyweightFactory struct {
	pool map[string]*Flyweight
}

func NewFlyweightFactory() *FlyweightFactory {
	return &FlyweightFactory{pool: make(map[string]*Flyweight)}
}

func (f *FlyweightFactory) GetFlyweight(name string) *Flyweight {
	weight, ok := f.pool[name]
	if !ok {
		weight = NewFlyweight(name)
		f.pool[name] = weight
	}
	return weight
}
